<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j"
	template="/WEB-INF/esquema/plantillasimple.xhtml">

	<ui:define name="body">
		<h:form>
			<a4j:keepAlive beanName="usersHelper"/>
			<div align="center">
				<h3>#{messages['user.management']}</h3>
				<br />
				<rich:separator/>
				<br />
				
				<a4j:commandLink
					value="#{messages['user.newuser']}" action="#{usersHelper.newUser}"
					oncomplete="#{rich:component('addUserDlg')}.show();"
					reRender="addUserDlg">
				</a4j:commandLink>
				
				<br />
				<br />
				<rich:dataTable id="dtUsers" value="#{usersHelper.users}" var="user" rowKeyVar="row">
					<rich:column>
						<f:facet name="header">#{messages['txt.user']}</f:facet>
						<h:outputText value="#{user.userName}" />
					</rich:column>
					<rich:column>
						<f:facet name="header">#{messages['txt.party_formal_identity']}</f:facet>
						<h:outputText value="#{user.party.formalIdentity}" />
					</rich:column>
					<rich:column>
						<f:facet name="header">#{messages['txt.full_name']}</f:facet>
						<h:outputText value="#{user.party.name}" />
					</rich:column>
					<rich:column>
						<f:facet name="header">#{messages['txt.type']}</f:facet>
						<h:outputText value="#{usersHelper.partyType(user)}" />
					</rich:column>
					<rich:column>
						<f:facet name="header">#{messages['txt.active']}</f:facet>
						<h:outputText value="#{user.active ? 'SI' : 'NO'}" />
					</rich:column>
					<rich:column>
						<f:facet name="header"></f:facet>
						<a4j:commandLink value="#{messages['button.edit']}"
							action="#{usersHelper.editUser(user)}"
							oncomplete="#{rich:component('editUserDlg')}.show();"
							reRender="editUserDlg">
						</a4j:commandLink>
					</rich:column>
					<rich:column>
						<f:facet name="header"></f:facet>
						<a4j:commandLink value="#{user.active ? messages['user.deactivate'] : messages['user.activate']}"
							action="#{usersHelper.toggleActivation(user)}"
							reRender="dtUsers">
							<f:setPropertyActionListener value="#{row}" target="#{usersHelper.currentRow}" />
						</a4j:commandLink>
					</rich:column>
				</rich:dataTable>
			</div>
		</h:form>
		
		<rich:modalPanel id="addUserDlg" minWidth="450" minHeight="490">
			<f:facet name="header">
				<h:outputText value="#{messages['user.editdata']}"/>
			</f:facet>
			
			<f:facet name="controls">
				<h:panelGroup>
					<h:graphicImage value="/img/close.png" styleClass="hidelink"
						id="hideAddUserDlg" />
					<rich:componentControl for="addUserDlg" attachTo="hideAddUserDlg"
						operation="hide" event="onclick" />
				</h:panelGroup>
			</f:facet>
			
			<h:form>
				<h:panelGroup rendered="#{usersHelper.selected != null}">
					<div align="center">
						<strong>#{messages['user.data']}</strong>
						<rich:separator lineType="solid"/>
						<br />
						<h:panelGrid columns="2" width="70%">
							<h:outputText value="#{messages['txt.user']}" />
							<h:inputText label="#{messages['txt.user']}"
							value="#{usersHelper.selected.userName}"
							required="true"
							style="width:95%">
								<f:validateLength minimum="3"/>
							</h:inputText>
						</h:panelGrid>
						<br />
						<br />

						<h:outputText value="#{messages['user.newuser_partyname']}:" />
						<br />
						<h:inputText
						id="partyName"
						value="#{usersHelper.newUserPartyName}"
						readonly="true"
						style="width:70%">
							<f:validateLength minimum="13" />
						</h:inputText>
						<a4j:commandLink ajaxSingle="true" oncomplete="#{rich:component('selectPartyPanel')}.show()">
							<f:setPropertyActionListener target="#{personHelper.returnValueField}" value="usersHelper.selected.party" />
							<f:setPropertyActionListener target="#{personHelper.reRenderComponents}" value="partyName" />
							<f:setPropertyActionListener target="#{legalPersonHelper.returnValueField}" value="usersHelper.selected.party" />
							<f:setPropertyActionListener target="#{legalPersonHelper.reRenderComponents}" value="partyName" />

							<h:outputText value="Seleccionar" />
						</a4j:commandLink>
						<br />
						<br />
					
						<ui:include src="rolesIncl.xhtml" />
						
						<br />
						<br />
						
						<strong>#{messages['user.newuser_intialpassword']}</strong>
						<rich:separator lineType="solid"/>
						<br />
						<h:panelGrid columns="2" width="70%">
							<h:outputText value="#{messages['txt.password']}" />
							<h:inputSecret
							label="#{messages['txt.password']}"
							value="#{usersHelper.password}"
							required="true">
								<f:validateLength minimum="5"/>
							</h:inputSecret>
							
							<h:outputText value="#{messages['user.confirm_password']}" />
							<h:inputSecret
							label="#{messages['user.confirm_password']}"
							value="#{usersHelper.confPassword}"
							required="true">
								<f:validateLength minimum="5"/>
							</h:inputSecret>
						</h:panelGrid>
						
						<br />
						
						<h:panelGrid columns="2" style="">
							<a4j:commandButton
								value="#{messages['button.ok']}"
								action="#{usersHelper.saveSelected}"
								oncomplete="if (#{facesContext.maximumSeverity == null}) #{rich:component('addUserDlg')}.hide(); else #{rich:component('msgPanel')}.show();"
								reRender="dtUsers">
							</a4j:commandButton>
							<a4j:commandButton
								value="#{messages['button.cancel']}"
								ajaxSingle="true"
								oncomplete="#{rich:component('addUserDlg')}.hide();">
							</a4j:commandButton>
						</h:panelGrid>
					</div>
				</h:panelGroup>
			</h:form>
		</rich:modalPanel>
		
		<rich:modalPanel id="editUserDlg" minWidth="450" minHeight="410" resizeable="false">
			<f:facet name="header">
				<h:outputText value="#{messages['user.editdata']}"/>
			</f:facet>
			
			<f:facet name="controls">
				<h:panelGroup>
					<h:graphicImage value="/img/close.png" styleClass="hidelink"
						id="hideEditDataPanel" />
					<rich:componentControl for="editUserDlg" attachTo="hideEditDataPanel"
						operation="hide" event="onclick" />
				</h:panelGroup>
			</f:facet>
			
			<rich:tabPanel switchType="client">
				<rich:tab label="#{messages['user.data']}">
					<h:form>
						<h:panelGroup rendered="#{usersHelper.selected != null}">
							<div align="center">
								<strong>#{messages['user.data']}</strong>
								<rich:separator lineType="solid"/>
								<h:panelGrid columns="2" width="70%">
									<h:outputText value="#{messages['txt.user']}" />
									<h:outputText value="#{usersHelper.selected.userName}" style="font-weight:bold;" />
		
									<h:outputLabel for="chkActive" value="#{messages['txt.active']}" />
									<h:selectBooleanCheckbox id="chkActive" value="#{usersHelper.selected.active}" />
								</h:panelGrid>
								<br />
								<h:panelGrid columns="2" width="100%">
									<h:outputText value="#{messages['txt.full_name']}" />
									<h:outputText value="#{usersHelper.selected.party.name}" style="font-weight:bold;" />
								</h:panelGrid>
								<br />
								
								<ui:include src="rolesIncl.xhtml" />
								
								<br />
								<br />
								
								<h:panelGrid columns="2" style="">
									<a4j:commandButton
										value="#{messages['button.ok']}"
										action="#{usersHelper.applyUserDataChange}"
										oncomplete="if (#{facesContext.maximumSeverity == null}) #{rich:component('editUserDlg')}.hide(); else #{rich:component('msgPanel')}.show();"
										reRender="dtUsers">
									</a4j:commandButton>
									<a4j:commandButton
										value="#{messages['button.cancel']}"
										ajaxSingle="true"
										oncomplete="#{rich:component('editUserDlg')}.hide();">
									</a4j:commandButton>
								</h:panelGrid>
							</div>
						</h:panelGroup>
					</h:form>
				</rich:tab>
				<rich:tab label="#{messages['user.reset_password']}">
					<h:form>
						<h:messages />
						<h:panelGroup rendered="#{usersHelper.selected != null}">
							<div align="center">
								<strong>#{messages['user.reset_password']}</strong>
								<rich:separator lineType="solid"/>
								<h:panelGrid columns="2">
									<h:outputText value="#{messages['user.new_password']}" />
									<h:inputSecret value="#{usersHelper.password}" />
									
									<h:outputText value="#{messages['user.confirm_password']}" />
									<h:inputSecret value="#{usersHelper.confPassword}" />
								</h:panelGrid>
								
								<br />
								<br />
								
								<h:panelGrid columns="2" style="">
									<a4j:commandButton
										value="#{messages['button.ok']}"
										action="#{usersHelper.saveSelected}"
										oncomplete="if (#{facesContext.maximumSeverity == null}) #{rich:component('editUserDlg')}.hide(); else #{rich:component('msgPanel')}.show();"
										reRender="dtUsers">
									</a4j:commandButton>
									<a4j:commandButton
										value="#{messages['button.cancel']}"
										ajaxSingle="true"
										oncomplete="#{rich:component('editUserDlg')}.hide();">
									</a4j:commandButton>
								</h:panelGrid>
							</div>
						</h:panelGroup>
					</h:form>
				</rich:tab>
			</rich:tabPanel>
		</rich:modalPanel>
		
		
		<ui:include src="/WEB-INF/includes/selectParty.xhtml" />
	</ui:define>
</ui:composition>
	
